// 实现了侧边查询的功能
map.on('singleclick', function (evt) {
  document.getElementById('info').innerHTML = '';
  var viewResolution = /** @type {number} */ (view.getResolution());
  var url = wmsSource.getFeatureInfoUrl(
    evt.coordinate, viewResolution, 'EPSG:3857',
    //   'FEATURE_COUNT': 1 最大查询图层数量，这样一口气可以查询同一个位置的两个图层 
    { 'INFO_FORMAT': 'text/html', 'FEATURE_COUNT': 2 }
  );
  if (url) {
    fetch(url)
      .then(function (response) { return response.text(); })
      .then(function (html) {
        document.getElementById('info').innerHTML = html;
      });
  }
});

map.on('pointermove', function (evt) {
  if (evt.dragging) {
    return;
  }
  var pixel = map.getEventPixel(evt.originalEvent);
  var hit = map.forEachLayerAtPixel(pixel, function () {
    return true;
  });
  map.getTargetElement().style.cursor = hit ? 'pointer' : '';
});

// 实现了图层切换功能
var change = function() {
  var layers = map.getLayers()
  var params = wmsSource.getParams()
  params.LAYERS = ['boundary']
  wmsLayer.source = wmsSource
  layers = [wmsSource]
}
